/*
 * @Author: your name
 * @Date: 2021-03-15 15:50:34
 * @LastEditTime: 2021-11-25 19:17:40
 * @LastEditors: LVGRAPE
 * @Description: In User Settings Edit
 * @FilePath: \Mixly_FOR__ZINO\arduino\hardware\UAVI_TECH\ZINO\cores\ZINO_IAP\motor.h
 */
#ifndef _MOTOR_H_
#define _MOTOR_H_
#include "at32f4xx.h"
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif 
typedef enum MOTOR_PORTS{
    MAIN_MOTOR = 0,//主电机口，可以正反转
    EXTEND_MOTOR,//扩展电机口，只能单向转动
    EXTEND_PWM,//扩展PWM口
    MOTOR_PORT_COUNT,
}MOTOR_PORTS_e;
typedef enum DRIVE_TYPE
{
    BRUSH_MOTOR=0,
    BRUSHLESS_MOTOR,
}DRIVE_TYPE_E;
typedef enum MAIN_MOTORS
{
    MAIN_MOTOR_1=0,
    MAIN_MOTOR_2,
    MAIN_MOTOR_3,
    MAIN_MOTOR_4,
    MAIN_MOTOR_COUNT,
}MAIN_MOTORS_e;
typedef enum EXTEND_MOTOR
{
    EXTEND_MOTOR_1 =0,
    EXTEND_MOTOR_2,
    EXTEND_MOTOR_3,
    EXTEND_MOTOR_4,

}EXTEND_MOTORS_E;
typedef enum EXTEND_PWM
{
    EXTEND_PWM_1=0,
    EXTEND_PWM_2,
    EXTEND_PWM_3,
    EXTEND_PWM_4,
    EXTEND_PWM_5,
    EXTEND_PWM_6,
}EXTEND_PWM_e;
typedef struct motor_parameter
{
    uint16_t clock_div;
    uint16_t clock_period;
    uint16_t freq;
    uint16_t minDuty;
    uint16_t maxDuty;
    uint8_t state;
}motor_port_property_s;
typedef enum{
    MOTOR_1=1,
    MOTOR_2,
    MOTOR_3,
    MOTOR_4,
    MOTOR_5,
    MOTOR_6,
    MOTOR_7,
    MOTOR_8,
    MOTOR_9,
    MOTOR_COUNT,
}MOTOR_TYPE;
typedef enum{
    SERVO_1=7,
    SERVO_2,
    SERVO_3,
}SERVO_TYPE;

void TMRx_Clock_Init(TMR_Type* TMRx, uint32_t _DIV, uint32_t _Period);
void TMRx_PWM_Channelx_Init(TMR_Type* TMRx);
void main_motor_init(DRIVE_TYPE_E driveType, uint16_t freq, uint16_t minDuty, uint16_t maxDuty);
void main_motor_port_output(MAIN_MOTORS_e port, int16_t throttle);
void motor_init(void);
void extend_motor_port_output(EXTEND_MOTORS_E port, int16_t throttle);
void extend_pwm_port_output(EXTEND_PWM_e port, int16_t throttle);
void extend_pwm_port_state(EXTEND_PWM_e port, bool on_off);
void motor_speed(MOTOR_TYPE motorx, int16_t speed);
void Set_Servo_Degree(SERVO_TYPE servo, uint8_t degree, uint8_t NewState);
void motor_output_init_all(MOTOR_PORTS_e motorPort, DRIVE_TYPE_E diriveType, uint16_t freq, uint16_t minDuty, uint16_t maxDuty);
void extend_motor_test(uint16_t m1,uint16_t m2,uint16_t m3,uint16_t m4);
bool get_extend_pwm_port_state(EXTEND_PWM_e port);
extern motor_port_property_s motor_port[MOTOR_PORT_COUNT];
#ifdef __cplusplus
}
#endif 

#endif // !_MOTOR_H_